package com.aha.dataanalyzeandview.controller;

import com.aha.dataanalyzeandview.entity.base.ResultEntity;
import com.aha.dataanalyzeandview.entity.stock.StockBaseFinancialDataEntity;
import com.aha.dataanalyzeandview.entity.stock.StockDetailsInfoEntity;
import com.aha.dataanalyzeandview.service.IValueRecommendService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

/******************************
 * Project:           data-analyze-and-view
 * FileName:          valueRecommendController.java
 * ClassName:         valueRecommendController
 * Time:              2020/8/17 22:25
 * Version:           1.00
 * Author:            努力就是魅力
 * Description:       TODO
 ******************************/

@Slf4j
@RestController
@RequestMapping(value = "/valueRecommend")
public class ValueRecommendController {

    @Autowired
    private IValueRecommendService valueRecommendService;


    /**
     * 查询股票数据，本身带有一定的排序，筛选。
     * @param stockDetailsInfoEntity
     * @return
     */
    @GetMapping(value = "/queryStockDetailsByCondition")
    public ResultEntity queryStockDetailsByCondition(StockDetailsInfoEntity stockDetailsInfoEntity){
        List<StockDetailsInfoEntity> stockDetailsInfoEntities =  valueRecommendService.queryStockDetailsAndMainIndexByCondition(stockDetailsInfoEntity);
        return ResultEntity.success(stockDetailsInfoEntities);
    }


    /**
     * 查询股票数据，本身带有一定的排序，筛选。
     * @param stockBaseFinancialDataEntity
     * @return
     */
    @GetMapping(value = "/queryStockBaseFinancialDataCondition")
    public ResultEntity queryStockBaseFinancialDataCondition(StockBaseFinancialDataEntity stockBaseFinancialDataEntity){
        List<StockBaseFinancialDataEntity> stockDetailsInfoEntities =  valueRecommendService.queryStockBaseFinancialDataCondition(stockBaseFinancialDataEntity);
         ResultEntity res =  ResultEntity.success(stockDetailsInfoEntities);
         res.setCount(stockDetailsInfoEntities.size());
         return res;
    }


    /**
     * 导入股票数据
     * @param file
     * @return
     */
    @ResponseBody
    @PostMapping(value = "/importStockInfo")
    public ResultEntity importStockInfo(@RequestParam("file") MultipartFile file) {

        int res = valueRecommendService.importStockInfo(file);
        return res > 0 ? ResultEntity.success() : ResultEntity.error(-12,"导入股票主要指标失败！");
    }


    /**
     * 导入基础财务数据
     * @param file
     * @return
     */
    @ResponseBody
    @PostMapping(value = "/importBasicFinancialData")
    public ResultEntity importBasicFinancialData(@RequestParam("file") MultipartFile file){
        int res = valueRecommendService.importBasicFinancialData(file);
        return res > 0 ? ResultEntity.success() : ResultEntity.error(-12,"导入股票基本财务数据失败！");
    }



}
